#!/bin/bash
#git pull oschina open-source
if [ "skip" != "$2" ]
then
mkdir -p release/dependency
mkdir -p release/classes

rm -rf release/dependency/*
rm -rf target/dependency/*

cd mammuthus-core
mvn dependency:copy-dependencies
cp -r target/dependency/* ../release/dependency/

echo "开始编译"
mvn clean  compile -DskipTests=true

if [ $? != 0 ];then
    echo "编译失败**********************************************************************************"
    exit 1
fi
cp -r target/classes/* ../release/classes/
cd ..
fi
if [ "test" == "$1" ]
then
echo `pwd`
rm -rf mammuthus-agent
mkdir mammuthus-agent
rm  mammuthus-agent-1.0.0.tar.gz
for f in bin config template release plugins
do
cp -r $f mammuthus-agent/
done
rm -rf mammuthus-agent/template/assets/
tar czvf mammuthus-agent-1.0.0.tar.gz mammuthus-agent/
cp -f mammuthus-agent-1.0.0.tar.gz template/assets/
cp -f mammuthus-agent-1.0.0.tar.gz /data/1/usr/local/
cp -f mammuthus-agent-1.0.0.tar.gz /data/1/usr/local/docker/mammuthus-agent/
oldPath=`pwd`
cd /data/1/usr/local/mammuthus-agent
./bin/deploy.sh stop
rm -rf /data/1/usr/local/mammuthus-agent
cd /data/1/usr/local
tar xzvf mammuthus-agent-1.0.0.tar.gz
cd /data/1/usr/local/mammuthus-agent
./bin/deploy.sh deploy
./bin/deploy.sh start
echo "build mammuthus-agent-1.0.0.tar.gz success"
fi
